#include "Time.hpp"

long long Time::asSeconds() {
	return value / 1000000000;
}

long long Time::asMilliseconds() {
	return value / 1000000;
}

long long Time::asMicroseconds() {
	return value / 1000;
}

long long Time::asNanoseconds() {
	return value;
}

Clock::Clock() {
	m_lastTP = std::chrono::steady_clock::now();
}

Time Clock::restart() {
	auto t = std::chrono::steady_clock::now();
	Time i(std::chrono::duration_cast<std::chrono::nanoseconds>(t - m_lastTP)
		.count());
	m_lastTP = t;
	return i;
}

Time Clock::getElapsedTime() {
	return std::chrono::duration_cast<std::chrono::nanoseconds>(
		std::chrono::steady_clock::now() - m_lastTP).count();
}

std::string getDate() {
	char buffer[16];
	time_t now = time(nullptr);
	strftime(buffer, sizeof buffer, "%d/%m/%Y", localtime(&now));
	return buffer;
}

/*
std::string getTime() {
	char buffer[16];
	time_t now = time(nullptr);
	strftime(buffer, sizeof buffer, "%X", localtime(&now));
	return buffer;
}*/
//linux = localtime_r
/*
tm_sec	int	seconds after the minute	0-60*
tm_min	int	minutes after the hour	0-59
tm_hour	int	hours since midnight	0-23
tm_mday	int	day of the month	1-31
tm_mon	int	months since January	0-11
tm_year	int	years since 1900
tm_wday	int	days since Sunday	0-6
tm_yday	int	days since January 1	0-365
tm_isdst	int	Daylight Saving Time flag
*/
std::tm * getTime() {
	time_t t = time(0);
	std::tm *tm;
	localtime_s(tm, &t);
	return tm;
}
